﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DBUtility;
using IDAL;
using Model;

namespace DAL
{
    public class DiagnoseBottleneck :BaseRepository_DT<ProductType_QInfo>, IDiagnoseBottleneck
    {
        #region 静态变量部分
        #endregion

        #region 数据检索与参数部分
        public IList<ProductType_QInfo> GetQ_dt_pt(DateTime starttime, DateTime stoptime)
        {
            SqlParameter[] testParms = GetDTParameters();
            //Bind the parameter
            testParms[0].Value = starttime;
            testParms[1].Value = stoptime;
            return ExcuteSqlToGetEntities("DiagnoseBottleneck_dt_pt", testParms);
        }

        public IList<ProductType_QInfo> GetQ_pt_tm(DateTime starttime, DateTime stoptime)
        {
            SqlParameter[] testParms = GetDTParameters();
            //Bind the parameter
            testParms[0].Value = starttime;
            testParms[1].Value = stoptime;
            return ExcuteSqlToGetEntities("DiagnoseBottleneck_pt_tm", testParms);
        }

        public IList<ProductType_QInfo> GetQ_tm_pt(DateTime starttime, DateTime stoptime)
        {
            SqlParameter[] testParms = GetDTParameters();
            //Bind the parameter
            testParms[0].Value = starttime;
            testParms[1].Value = stoptime;
            return ExcuteSqlToGetEntities("DiagnoseBottleneck_tm_pt", testParms);
        }

        /// <summary>
        /// 时间段内各工序各产品类型产能情况统计
        /// </summary>
        /// <returns></returns>
        public IList<ProductType_AllQInfo> GetAllProductionDT(DateTime starttime, DateTime stoptime)
        {
            IList<ProductType_AllQInfo> Entities = new List<ProductType_AllQInfo>();
            SqlParameter[] testParms = GetDTParameters();
            //Bind the parameter
            testParms[0].Value = starttime;
            testParms[1].Value = stoptime;
            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "DiagnoseBottleneck_ProductionAllProcess", testParms))
            {
                while (rdr.Read())
                {
                    ProductType_AllQInfo Entity = new ProductType_AllQInfo
                    {
                        CustomerName = rdr.GetValue(0).ToString(),
                        ProductTypeID = rdr.GetValue(1).ToString(),
                        AQ = rdr.GetInt32(2),
                        DTQ = rdr.GetInt32(3),
                        DTWQ = rdr.GetInt32(4),
                        PIMQ=rdr.GetInt32(5),
                        TQ = rdr.GetInt32(6),
                        PTQ = rdr.GetInt32(7)
                    };
                    Entities.Add(Entity);
                }
            }
            return Entities;
        }
        #endregion

        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override ProductType_QInfo GetEntityRecord(SqlDataReader rdr)
        {
            ProductType_QInfo pro = new ProductType_QInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetInt32(2));
            return pro;
        }
        #endregion
    }
}
